package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Host;
import po.HostCustom;
import po.Result;
import service.HostService;

import java.util.List;

@Controller
@RequestMapping("/host")
public class HostController {
    @Autowired
    private HostService hostService;

    @RequestMapping("/getHostInfoView")
    public String getHostInfoView() {
        return "resource/hostInfo";
    }

    @RequestMapping("/findAllHostCustom")
    public @ResponseBody
    List<HostCustom> findAllHostCustom() throws Exception {
        return hostService.findAllHostCustom();
    }

    @RequestMapping("/getAddHostView")
    public String getAddHostView() {
        return "resource/addHost";
    }

    @RequestMapping("/addHost")
    public @ResponseBody
    Result addHost(Host host) {
        return hostService.addHost(host);
    }

    @RequestMapping("/deleteHostById")
    public @ResponseBody
    Result deleteHostById(int id) {
        return hostService.deleteHostById(id);
    }

    @RequestMapping("/getEditHostView")
    public String getEditHostView() {
        return "resource/editHost";
    }

    @RequestMapping("/updateHost")
    public @ResponseBody
    Result updateHost(Host host) {
        return hostService.updateHostById(host.getId(), host);
    }

    @RequestMapping("/findHostById")
    public @ResponseBody
    Host findHostById(int id) throws Exception {
        return hostService.findHostById(id);
    }
}
